package org.example.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.springcloud.entities.Payment;
import org.example.springcloud.result.CommonResult;
import org.example.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 *
 * @author Jandmla
 * Date: 2022/7/22
 * Time: 14:15
 * Description:
 */
@RestController
@Slf4j
public class PaymentControllerImpl{

    private final PaymentService paymentService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @Value("${server.port}")
    private String serverPort;

    public PaymentControllerImpl(PaymentService paymentService){
        this.paymentService = paymentService;
    }

    /**
     * 正常请求
     * @param id id
     * @return 结果
     */
    @GetMapping("/payment/hystrix/ok/{id}")
    public CommonResult<String> paymentInfo_OK(@PathVariable("id") Long id){
        String result = paymentService.paymentInfo_OK(id);
        log.info("********result:{}***********",result);
        return new CommonResult<>(200,"请求成功！",result);
    }

    /**
     * 超时请求
     * @param id id
     * @return 结果
     */
    @GetMapping("/payment/hystrix/timeout/{id}")
    public CommonResult<String> paymentInfo_TimeOut(@PathVariable("id") Long id){
        String result = paymentService.paymentInfo_TimeOut(id);
        log.info("********result:{}***********",result);
        return new CommonResult<>(200,"请求成功！",result);
    }

}